pp108 : XPath Parser, XPath Object and XPath Output

XPath Parser, XPath Object and XPath Output

This topic describes the concepts of XPath Parser, XPath Object, and XPath Output.

XPath Parser


XPath Parser is a library comprising a parser for XPath expressions, and a set of classes which are used to represent the structure of the expressions. All XPath expressions are parsed to a syntax tree (a binary tree) inside which, the lookup mechanism is embedded. This parser creates class-based structure of an XPath expression which may be manipulated as required.
One of the following search methods is selected based on the given expression:

  • Breadth First Search (BFS)
  • Depth First Search (DFS)
  • A combination of both

XPath Object


After an XPath expression is parsed, the XPath object created with the syntax tree is placed inside it. This syntax tree is used to evaluate the XPath expression for a given input. The syntax tree is also cached by the engine for later use (get multiple XPath objects with the same syntax tree when the same expression is used iteratively). The syntax tree remains in the cache even when the XPath object is deleted. The generated XPath object is thread-safe and can be shared across multiple threads.

The generated XPath object is used to find nodes in a given NOM tree, as specified by the XPath expression. The XPath object containing the lookup criteria performs the lookup in NOM tree.

XPath Output

The output is the XPathResult object that contains any of the following types, as defined by XPath1.0 specifications:

  • Boolean
  • Nodeset
  • Number
  • String
  • Custom (User defined)

    Note: Nodeset contains XPathResultNode objects that are wrappers for the selected nodes of the NOM tree.

Related reference

Defining XPath Expressions
Understanding XPath Expressions
Optimizing XPath Expression Usage
Using XPath API

Related information

Overview of XPath